﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using FBroSharp;
using FBroSharp.Const;
using FBroSharp.DataType;
using FBroSharp.Lib;
using FBroSharp.Value;

namespace BaseTest
{
    public partial class Form1 : Form
    {
        private int menu_height;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            menu_height = this.menuStrip1.Height;

            //创建浏览器
            BrowserDis.CreatBrowser("百度", "https://www.baidu.com/", this.Handle, 0, menu_height, this.ClientSize.Width, this.ClientSize.Height);
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            for (int i = 0; i < BrowserList.data.Count; i++)
            {
                BrowserList.data[i].MoveWindow(0, menu_height, this.ClientSize.Width, this.ClientSize.Height, true);

            }
        }

        private void 浏览器测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 创建后台浏览器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //创建浏览器事件回调类
            BrowserEvent browser_event = new BrowserEvent();

            //设置传递参数
            FBroSharpDictionaryValue extra_info = new FBroSharpDictionaryValue();//.Creat();
            extra_info.SetBool("是否为后台", true);

            FBroSharpControl.CreateBackground("https://www.qq.com", default, default /*request_context*/, extra_info, browser_event, default/*event_contrl*/);
        }

        private void 当前窗口创建ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < BrowserList.data.Count; i++)
            {
                BrowserList.data[i].CloseBrowser(false, false);
            }


            BrowserDis.CreatBrowser("腾讯", "https://www.qq.com", this.Handle, 0, menu_height, this.Width, this.Height - menu_height);
        }

        private void 创建弹窗ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserDis.CreatBrowser("腾讯", "https://www.qq.com", default, 0, menu_height, this.Width, this.Height - menu_height);
        }

        private void webGL检测ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserDis.CreatBrowser("webGL检测", "https://get.webgl.org", default, 0, menu_height, this.Width, this.Height - menu_height);
        }

        private void 浏览器指纹检测ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserDis.CreatBrowser("指纹检测", "https://gongjux.com/fingerprint/", default, 0, menu_height, this.Width, this.Height - menu_height);
        }

        private void 是否能后退ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("是否能后退：" + BrowserList.data[0].CanGoBack());
        }

        private void 后退ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GoBack();
        }

        private void 是否能前进ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("是否能前进：" + BrowserList.data[0].CanGoForward());
        }

        private void 前进ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GoForward();
        }

        private void 读取中ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("读取中：" + BrowserList.data[0].IsLoading());
        }

        private void 重新加载ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].Reload();
        }

        private void 忽略缓存重新加载ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 停止加载ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].StopLoad();
        }

        private void 取IDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("浏览器ID：" + BrowserList.data[0].GetIdentifier());
        }

        private void 是否一样ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //这个肯定是一样的，除非有问题才会不一样
            Console.WriteLine("是否一样：" + BrowserList.data[0].IsSame(BrowserList.data[0]));
        }

        private void 是否为弹窗ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("是否为弹窗：" + BrowserList.data[0].IsPopup());
        }

        private void 是否为文档ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("是否为文档：" + BrowserList.data[0].HasDocument());
        }

        private void 取主框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frame = BrowserList.data[0].GetMainFrame();
            Console.WriteLine("主框架ID：" + frame.GetIdentifier().ToString());
        }

        private void 取当前焦点框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var frame = BrowserList.data[0].GetFocusedFrame();
            Console.WriteLine("当前焦点框架ID：" + frame.GetIdentifier().ToString());
        }

        private void 通过ID取框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = BrowserList.data[0].GetFrameIdentifiers();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("框架名：" + BrowserList.data[0].GetFrameById(list[i]).GetName());
            }
        }

        private void 通过名字取框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = BrowserList.data[0].GetFrameNames();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("框架ID：" + BrowserList.data[0].GetFrameByName(list[i]).GetIdentifier());
            }
        }

        private void 取框架数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("框架数：" + BrowserList.data[0].GetFrameCount());
        }

        private void 取框架IDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = BrowserList.data[0].GetFrameIdentifiers();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("框架ID：" + list[i]);
            }
        }

        private void 取框架名ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var list = BrowserList.data[0].GetFrameNames();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("框架名：" + list[i]);
            }
        }

        private void 取请求环境ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var context = BrowserList.data[0].GetRequestContext();
            Console.WriteLine("请求环境缓存目录：" + context.GetCachePath());
        }

        private void 清理缓存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearCacheCallback callback = new ClearCacheCallback
            {
                flag = BrowserList.data[0].GetIdentifier()
            };

            //如果浏览不是独立缓存，这里清理的缓存其实和全局是一样的
            BrowserList.data[0].ClearCacheData("", FBroSharpRemoveData.REMOVE_DATA_MASK_ALL, FBroSharpCacheType.QUOTA_MANAGED_STORAGE_MASK_ALL, callback);
        }

        private void 清理缓存全局ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearCacheCallback callback = new ClearCacheCallback();
            FBroSharpBrowser.ClearGlobalCacheData("", FBroSharpRemoveData.REMOVE_DATA_MASK_ALL, FBroSharpCacheType.QUOTA_MANAGED_STORAGE_MASK_ALL, callback);
        }

        private void 是否已关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("浏览是否已关闭：" + !BrowserList.data[0].IsLife());
        }

        private void 浏览器HOST测试ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 关闭浏览器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].CloseBrowser(false, false);
        }

        private void 尝试关闭ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("尝试关闭：" + BrowserList.data[0].TryCloseBrowser(false));
        }

        private void 置焦点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].SendFocusEvent(true);
        }

        private void 取窗口句柄ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("窗口句柄：" + BrowserList.data[0].GetWindowHandle());
            Console.WriteLine("窗口标题：" + BrowserList.data[0].GetWindowsTitle());
        }

        private void 取打开者窗口句柄ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //这个只有当前是子浏览器时去处打开子浏览器的浏览器的句柄
            Console.WriteLine("取打开者句柄：" + BrowserList.data[0].GetOpenerWindowHandle());
        }

        private void 是否为视图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("是否为视图：" + BrowserList.data[0].HasView());
        }

        private void 设置缩放ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].SetZoomLevel(1.1);
        }

        private void 取缩放级别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("当前缩放：" + BrowserList.data[0].GetZoomLevel());
        }

        private void 开始下载ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].StartDownload("https://www.baidu.com");
        }

        private void 下载图片ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpDownloadImageCallbackDis callback = new FBroSharpDownloadImageCallbackDis();
            BrowserList.data[0].DownloadImage("https://www.baidu.com/img/flexible/logo/pc/result.png", false, 0, true, callback);
        }

        private void 打开文件选择对话框ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpFileDialogCallbackDis callback = new FBroSharpFileDialogCallbackDis();
            BrowserList.data[0].RunFileDialog(FBroSharpFileDialogModeType.FILE_DIALOG_OPEN, "打开对话框", Directory.GetCurrentDirectory(), default, callback);
        }

        private void 打印ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].Print();
        }

        private void 打印为PDFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpPdfPrintCallbackDis callback = new FBroSharpPdfPrintCallbackDis();
            BrowserList.data[0].PrintToPDF(FBroSharpPdfPrintMargintype.PDF_PRINT_MARGIN_DEFAULT, Directory.GetCurrentDirectory() + "\\print.pdf", default, default, default, true, callback);
        }

        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].Find("百度", true, false, true);
        }

        private void 停止查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].StopFinding(true);
        }

        private void 打开开发者工具ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].ShowDevTools("开发者工具", IntPtr.Zero, 0, 0, 500, 500, default, default, default, default);
        }

        private void 关闭开发者工具ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (BrowserList.data[0].HasDevTools())
                BrowserList.data[0].CloseDevTools();
        }

        private void 是否为开发者工具ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].IsDevTools());
        }

        private void 发送按键事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpKeyEvent key_event = new FBroSharpKeyEvent
            {
                //ctrl
                modifiers = FBroSharpEventFlags.EVENTFLAG_CONTROL_DOWN,
                //A键盘
                windows_key_code = 65
            };

            BrowserList.data[0].SendKeyEvent(key_event);
        }

        private void 发送鼠标按键事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpMouseEvent mouserEvent = new FBroSharpMouseEvent
            {
                x = 32,
                y = 32,
                modifiers = FBroSharpEventFlags.EVENTFLAG_NONE
            };
            //按下
            BrowserList.data[0].SendMouseClickEvent(FBroSharpMouseButtonType.MBT_LEFT, mouserEvent, false, 1);
            //放开
            BrowserList.data[0].SendMouseClickEvent(FBroSharpMouseButtonType.MBT_LEFT, mouserEvent, true, 1);
        }

        private void 发送鼠标移动事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpMouseEvent mouserEvent = new FBroSharpMouseEvent
            {
                x = 100,
                y = 100,
                modifiers = FBroSharpEventFlags.EVENTFLAG_NONE
            };
            BrowserList.data[0].SendMouseMoveEvent(mouserEvent, false);
        }

        private void 发送鼠标滚轮事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpMouseEvent mouserEvent = new FBroSharpMouseEvent
            {
                x = 100,
                y = 100,
                modifiers = FBroSharpEventFlags.EVENTFLAG_NONE
            };
            BrowserList.data[0].SendMouseWheelEvent(mouserEvent, -10, -10);
        }

        private void 发送触摸事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpTouchEvent touchEvent = new FBroSharpTouchEvent
            {
                type = FBroTouchEventType.CEF_TET_PRESSED,
                x = 358,
                y = 214,
                radius_x = 100,
                radius_y = 100
            };
            BrowserList.data[0].SendTouchEvent(touchEvent);
        }

        private void 发送焦点事件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].SetFocus(true);
        }

        private void 设置页面静音ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].SetAudioMuted(true);
        }

        private void 页面是否静音ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].IsAudioMuted());
        }

        private void 设置父窗口ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //设置父窗口为0，相当于不嵌入窗口，可利用这个实现全屏
            BrowserList.data[0].SetParent(IntPtr.Zero);
        }

        private void 取窗口风格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetWinLong(FBroWinLongType.GWL_STYLE));
        }

        private void 置窗口风格ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const long WS_POPUP = 2147483648;
            const long WS_EX_TOOLWINDOW = -2138570752;
            long old = BrowserList.data[0].GetWinLong(FBroWinLongType.GWL_STYLE);
            BrowserList.data[0].SetWinLong(FBroWinLongType.GWL_STYLE, old | WS_POPUP | WS_EX_TOOLWINDOW);
        }

        private void 是否有效ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().IsValid);
        }

        private void 取地址ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().GetURL());
        }

        private void 载入地址ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://www.qq.com");
        }

        private void 载入数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string data = "<html><head><meta charset=\"UTF-8\"><title>Test Cef</title></head>"
                     + "<body bgcolor= \"white\">"
                     + "<h2>你好FBrowser！！！</h2>"
                     + "<a style='color:#00ff00'>这是一个直接将网页数据载入的例子！</a>"
                     + "<div style='color:red'>这里是个div</div>"
                     + "<a href='https://www.baidu.com'>打开百度网页</a>"
                     + "</body>"
                     + "<script>alert('你好FBrowser')</script></html>";

            string uri = FBroSharpControl.GetDataURI("text/html", data);

            BrowserList.data[0].GetMainFrame().LoadURL(uri);
        }

        private void 源码视图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().ViewSource();
        }

        private void 选择全部ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().SelectAll();
        }

        private void 取源码异步ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpStringVisitorDis callback = new FBroSharpStringVisitorDis
            {
                type = "获取文本"
            };
            BrowserList.data[0].GetMainFrame().GetSource(callback);
        }

        private void 取文本异步ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpStringVisitorDis callback = new FBroSharpStringVisitorDis
            {
                type = "获取文本"
            };
            BrowserList.data[0].GetMainFrame().GetSource(callback);
        }

        private void 是否主框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().IsMain());
        }

        private void 是否焦点框架ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().IsFocused());
        }

        private void 取框架名ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().GetName());
        }

        private void 取框架IDToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Console.WriteLine(BrowserList.data[0].GetMainFrame().GetIdentifier());
        }

        private void 载入请求GETToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //设置协议头数据
            FBroSharpStringMap hardmap = new FBroSharpStringMap
            {
                key = "Accept",
                value = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
            };

            //创建请求
            FBroSharpRequest request = new FBroSharpRequest();
            request.Set("https://www.baidu.com/s?wd=1231", "GET", default, hardmap);

            //载入请求
            BrowserList.data[0].GetMainFrame().LoadRequest(request);
        }

        private void 载入请求POSTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //设置协议头数据
            FBroSharpStringMap hardmap = new FBroSharpStringMap
            {
                key = "Accept",
                value = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
            };

            //创建post元素
            FBroSharpPostDataElement element = new FBroSharpPostDataElement();
            element.SetToString("username=账号&password=密码&");

            //创建post数据
            FBroSharpPostData postData = new FBroSharpPostData();
            postData.AddElement(element);

            //创建请求
            FBroSharpRequest request = new FBroSharpRequest();
            request.SetReferrer("https://www.baidu.com", FBroSharpReferrerPolicyType.REFERRER_POLICY_DEFAULT);
            request.Set("https://passport.baidu.com/v2/api/?login", "POST", postData, hardmap);

            //载入请求
            BrowserList.data[0].GetMainFrame().LoadRequest(request);
        }

        private void 发送进程消息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpProcessMessage message = new FBroSharpProcessMessage("message");
            var list = message.GetArgumentList();
            list.SetString(0, "this is process message");
            BrowserList.data[0].GetMainFrame().SendProcessMessage(FBroSharpProcessId.PID_RENDERER, message);
        }

        private void 执行JS代码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().ExecuteJavaScript("alert('你好 FBrowser!');", default, default);
        }

        private void 执行JS代码带返回值ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpJsCallbackDis callback = new FBroSharpJsCallbackDis();

            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("document.getElementById('form').clientHeight", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){var a=1.1;return a;};a();", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){var a=100;return a;};a();", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){var day1 = new Date(); var a=day1.getTime();return day1;};a();", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){var a='abcd';return a;};a();", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){console.log('nothing');}a();", default, default, callback);
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("test", default, default, callback);

        }

        private void 取CookieurlToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = FBroSharpCookieManager.GetGlobalManager();
            FBroSharpCookieVisitorDis callback = new FBroSharpCookieVisitorDis();
            manager.VisitUrlCookies("http://www.baidu.com/", false, callback);
        }

        private void 取Cookie全局ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = FBroSharpCookieManager.GetGlobalManager();
            FBroSharpCookieVisitorDis callback = new FBroSharpCookieVisitorDis();
            manager.VisitAllCookies(callback);
        }

        private void 置Cookie全局ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = FBroSharpCookieManager.GetGlobalManager();

            string url = "http://www.baidu.com";
            FBroSharpCookieData cookieData = new FBroSharpCookieData
            {
                name = "这是全局cookie",
                value = "这里没有值",
                domain = ".baidu.com",//这个不设置就是根域
                path = "/",
                httponly = false,
                has_expires = true,
                expires_time = new DateTime(2024, 6, 30, 23, 59, 00),
                last_access_time = new DateTime(2023, 6, 28, 5, 13, 00),
            };
            manager.SetCookie(url, cookieData);


            //FBroSharpCookieData cookieData1 = new FBroSharpCookieData
            //{
            //    name = "这是全局cookie1111",
            //    value = "这里没有值1111",
            //    domain = ".baidu.com",//这个不设置就是根域
            //    path = "/",
            //    httponly = false,
            //    has_expires = true,
            //    expires_time = new DateTime(2024, 6, 30, 23, 59, 00),
            //    last_access_time = new DateTime(2023, 6, 28, 5, 13, 00),
            //};
            //manager.SetCookie(url, cookieData1);

        }

        private void 取CookieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //如果是独立环境这里取出来的就是独立环境的cookie管理者，如果不是独立环境取出来的实际就是全局
            FBroSharpCookieManager manager = (FBroSharpCookieManager)BrowserList.data[0].GetRequestContext().GetCookieManager();
            FBroSharpCookieVisitorDis callback = new FBroSharpCookieVisitorDis();
            manager.VisitAllCookies(callback);
        }

        private void 置CookieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = (FBroSharpCookieManager)BrowserList.data[0].GetRequestContext().GetCookieManager();
            string url = "http://www.baidu.com";
            FBroSharpCookieData cookieData = new FBroSharpCookieData
            {
                name = "这是全局cookie",
                value = "这里没有值",
                domain = ".baidu.com",//这个不设置就是根域
                path = "/",
                httponly = false,
                has_expires = true,
                expires_time = new DateTime(2024, 6, 30, 23, 59, 00),
                last_access_time = new DateTime(2023, 6, 28, 5, 13, 00),
            };
            manager.SetCookie(url, cookieData);
        }

        private void 删除CookieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = FBroSharpCookieManager.GetGlobalManager();
            //删除全部
            manager.DeleteCookies("", "");
        }

        private void 刷新CookieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpCookieManager manager = FBroSharpCookieManager.GetGlobalManager();
            manager.FlushStore();
        }

        private void 跳转证书错误网站ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //这是个内网测试地址，如果你要测试需要换成你自己的地址
            BrowserList.data[0].GetMainFrame().LoadURL("https://172.29.24.3");
            //在浏览器事件OnCertificateError中返回真即可跳转
        }

        private void 取缓存目录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //取出全局环境
            IFBroSharpRequestContext global_context = FBroSharpRequestContext.GetGlobalContext();
            Console.WriteLine("全局缓存目录:" + global_context.GetCachePath());

            //取出浏览器环境，如果当前浏览器为全局这里的环境和上面全局环境一样，如果浏览器采用的独立缓存模式，这里取出的环境非全局环境
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            Console.WriteLine("浏览器缓存目录:" + browser_context.GetCachePath());

        }

        private void 是否全局ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            Console.WriteLine("是否为全局:" + browser_context.IsGlobal());
        }

        private void 取插件数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            Console.WriteLine("插件数:" + list.Count);
        }

        private void 取插件清单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("插件:" + i + ":" + list[i]);
            }
        }

        private void 已加载扩展插件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("已加载扩展插件:" + i + ":" + browser_context.DidLoadExtension(list[i]));
            }
        }

        private void 已访问扩展插件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("已加载扩展插件:" + i + ":" + browser_context.HasExtension(list[i]));
            }
        }

        private void 取插件信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            for (int i = 0; i < list.Count; i++)
            {
                IFBroSharpExtension extension = browser_context.GetExtension(list[i]);
                Console.WriteLine("已加载扩展插件:" + extension.GetIdentifier() + "-" + extension.GetPath());
            }
        }

        private void 卸载插件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFBroSharpRequestContext browser_context = BrowserList.data[0].GetRequestContext();
            List<string> list = browser_context.GetExtensionsList();
            for (int i = 0; i < list.Count; i++)
            {
                IFBroSharpExtension extension = browser_context.GetExtension(list[i]);
                //卸载插件
                extension.Unload();
            }
        }

        private void 创建服务器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpServerHandleDis callback = new FBroSharpServerHandleDis();
            FBroSharpServer.CreateServer("127.0.0.1", 8888, 100, callback);
        }

        private void 跳转测试地址ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("http://coolaf.com/tool/chattest");
        }

        private void 同步执行JSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //创建一个js回调类，这个类里面有个help变量用于等待数据返回
            FBroSharpJsCallbackSyn callback = new FBroSharpJsCallbackSyn();
            BrowserList.data[0].GetMainFrame().ExecuteJavaScriptToHasReturn("function a(){var a=1.1;return a;};a();", default, default, callback);
            if (callback.help != null && callback.help.IsValid)
            {
                //等待执行结果
                callback.help.WaitEvent(10 * 1000);

                //输出执行结果，这里的结果是回调中保存到help中的
                if (callback.help.HavDoubleData())
                    Console.WriteLine(callback.help.GetDoubleData());

                //清理全部数据，其实这里不需要处理，只是测试下，如果不需要了会自动释放
                callback.help.ClearData();
                Console.WriteLine(callback.help.HavDoubleData());
            }
        }

        private void 填表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取主填表框架
            IFBroSharpTianBiaoFrame tianbiao_frame = BrowserList.data[0].GetMainTianBiaoFrame();
            if (tianbiao_frame != null && tianbiao_frame.IsValid)
            {
                tianbiao_frame.SetValue("input[id*=\"kw\"]", 0, "FBrowserCEF3lib框架");

                //该回调和上面的同步测试方式一致
                FBroSharpJsCallbackSyn callback = new FBroSharpJsCallbackSyn();
                tianbiao_frame.GetPoint("input[id*=\"kw\"]", 0, callback);
                if (callback.help != null && callback.help.IsValid)
                {
                    //等待返回值，10秒超时
                    callback.help.WaitEvent(10 * 1000);
                    //输出返回数据
                    Console.WriteLine("坐标:" + callback.help.GetStringData());
                }
            }
        }

        private void toolStripTextBox1_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //开始创建浏览器
            FBroSharpWindowsInfo windows_info = new FBroSharpWindowsInfo
            {
                parent_window = IntPtr.Zero,
                x = 0,
                y = 0,
                width = 1024,
                height = 800,
                window_name = "独立缓存"
            };

            //创建浏览器事件回调类
            BrowserEvent browser_event = new BrowserEvent();

            //设置运行环境
            FBroSharpRequestContextSet contextSet = new FBroSharpRequestContextSet
            {
                cache_path = Directory.GetCurrentDirectory() + "\\Cache\\other cache\\"
            };

            FBroSharpRequestContext request_context = (FBroSharpRequestContext)FBroSharpRequestContext.CreateContext(contextSet);
            //Console.WriteLine("缓存目录:" + request_context.GetCachePath());

            //设置不需要的事件
            //FBroSharpEventDisableControl event_contrl = new FBroSharpEventDisableControl();
            //event_contrl.disableGetAudioHandler = true;


            //设置传递参数
            //FBroSharpDictionaryValue extra_info = new FBroSharpDictionaryValue();//.Creat();
            //extra_info.SetString("传参测试", "这是创建浏览器的时候传递过来的参数");

            if (FBroSharpControl.CreatBrowser("https://www.baidu.com", windows_info, default, request_context, default/*extra_info*/, browser_event, default/*event_contrl*/))
                Console.WriteLine("true");

        }

        private void 创建URL请求ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpRequest sharp_request = new FBroSharpRequest();
            sharp_request.SetURL("https://api.fbrowser.site:8443/");
            sharp_request.SetMethod("GET");

            //添加协议头，这里用list添加，只添加了一个UA
            List<FBroSharpStringMap> heard_list = new List<FBroSharpStringMap>();

            heard_list.Add(new FBroSharpStringMap
            {
                key = "User-Agent",
                value = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.97 Safari/537.36 Core/1.116.438.400 QQBrowser/13.0.6071.400"
            });

            sharp_request.SetHeaderMap_Array(heard_list);

            // FBroSharpRequestContext sharp_request_context;
            URLEvent sharp_event = new URLEvent();
            FBroSharpURLRequest.Create(sharp_request, default, sharp_event, 123456);
        }

        private void 创建框架URL请求ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FBroSharpRequest sharp_request = new FBroSharpRequest();
            sharp_request.SetURL("https://api.fbrowser.site:8443/");
            sharp_request.SetMethod("GET");

            // FBroSharpRequestContext sharp_request_context;
            URLEvent sharp_event = new URLEvent();

            var frame = BrowserList.data[0].GetMainFrame();
            frame.CreateURLRequest(sharp_request, sharp_event, 123456);
        }
    }


}
